package com.xiaochen.manager.controller;

import com.xiaochen.manager.service.SysMenuService;
import com.xiaochen.model.entity.system.SysMenu;
import com.xiaochen.model.vo.common.Result;
import com.xiaochen.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/system/sysMenu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 1.获取菜单列表
     */
    @GetMapping("/findNodes")
    public Result findNodes(){
        List<SysMenu> sysMenuList = sysMenuService.findNodes();
        return Result.build(sysMenuList, ResultCodeEnum.SUCCESS);
    }

    /**
     * 2.添加菜单
     */
    @PostMapping("/addSysMenu")
    public Result addSysMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.addSysMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 3.修改菜单
     */
    @PutMapping("/updateSysMenu")
    public Result updateSysMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.updateSysMenu(sysMenu);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 4.删除菜单
     */
    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable Long id){
        sysMenuService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 5.根据ID查询菜单
     */
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Long id){
        SysMenu sysMenu = sysMenuService.findById(id);
        return Result.build(sysMenu,ResultCodeEnum.SUCCESS);
    }
}
